﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Telerik.WinControls;
using libAddressBook.BUS;
using libDAL;

namespace libAddressBook.FORMS
{
    public partial class frmAddressBok : Telerik.WinControls.UI.RadForm
    {
        private clsMainBUSInterface _BUS;
        private DataRow[] drCompanyDetailsx = {}; 

        public frmAddressBok()
        {
            InitializeComponent();
        }

        private void radLabel30_Click(object sender, EventArgs e)
        {

        }

        ~frmAddressBok()
        { }

        private void cbbBranch_Click(object sender, EventArgs e)
        {
            frmAddressBookBranch frmBranch = new frmAddressBookBranch();
            frmBranch.ShowDialog(this);
        }

        private void btnUpdateAddress_Click(object sender, EventArgs e)
        {
            frmManageCompanyInfo frmAddressBook = new frmManageCompanyInfo();
            Point p = gbCredentials.PointToScreen(btnUpdateAddress.Location);
            frmAddressBook.set_NewLocation(p.X, p.Y + btnUpdateAddress.Height);
            frmAddressBook.ShowDialog();
        }

        public void set_AddressbookFields(string strCustomerID, string strCompanyType)
        {
            try
            {
                if (_BUS.set_CompanyDetails(strCustomerID, strCompanyType) == true)
                {
                    drCompanyDetailsx = _BUS.get_CompanyDetails(strCustomerID);
                    if (drCompanyDetailsx.Length > 0)
                    {
                        set_Fields();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_AddressbookFields"); 
            }
        }

        private void set_Fields()
        {
            try
            {
                txtID.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["comid"]).ToString().Trim();
                txtRegistrationNo.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["comregno"]).ToString().Trim();
                txtCompanyName.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["comname"]).ToString().Trim();
                txtAddressLine1.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["addline1"]).ToString().Trim();
                txtAddressLine2.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["addline2"]).ToString().Trim();
                txtAddressLine3.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["addline3"]).ToString().Trim();
                txtAddressLine4.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["addline4"]).ToString().Trim();
                txtCityCode.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["citycode"]).ToString().Trim();
                txtCountryCode.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["coucode"]).ToString().Trim();
                txtStateCode.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["stacode"]).ToString().Trim();
                txtAreaCode.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["areacode"]).ToString().Trim();
                txtPotalCode.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["poscode"]).ToString().Trim();
                txtPortID.Text = clsGenFunction.get_checkStringNull(drCompanyDetailsx[0]["portid"]).ToString().Trim();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " set_Fields"); 
            }
        }

        private void frmAddressBook_Load(object sender, EventArgs e)
        {
            _BUS = new clsMainBUSInterface();
            //this.ControlBox = false;
            //this.MinimizeBox = false;
            //this.MaximizeBox = false;
        }

        private void cbbOperational_Click(object sender, EventArgs e)
        {
            frmOperationalSettings x = new frmOperationalSettings();
            x.StartPosition = FormStartPosition.CenterScreen;
            x.ShowDialog();
        }

        private void frmAddressBook_FormClosed(object sender, FormClosedEventArgs e)
        {
            this.Dispose();
            GC.Collect();
            GC.WaitForFullGCComplete();
            GC.Collect();
        }

       
        private void radTextBox1_Click(object sender, EventArgs e)
        {
            //radTextBox1.SelectAll();
        }

       
    }
}
